<template>
  <div>
    <div class="search">
      <!-- 搜索 -->
      <el-input
        size="mini"
        style="width:180px"
        placeholder="账号"
        prefix-icon="el-icon-search"
        v-model="keyword"
      ></el-input>

      <!-- 变更类型 -->
      <el-select size="mini" class="datay" v-model="selection" placeholder="变更类型选择">
        <el-option @click="Changetype(item,code)" v-for="item in options" :key="item.value" :label="item.value" :value="item.code"></el-option>
      </el-select>
      <!-- 登录时间 -->
      <el-date-picker
        size="mini"
        class="datay"
        v-model="startTime"
        type="date"
        placeholder="开始时间"
        value-format="yyyy-MM-dd"
        @change="getSTime"
      ></el-date-picker>
      <span style="padding: 0 20px;">至</span>
      <el-date-picker
        size="mini"
        v-model="endTime"
        type="date"
        placeholder="结束时间"
        value-format="yyyy-MM-dd"
        @change="getSTime"
      ></el-date-picker>
      <!-- 确定 -->
      <el-button size="mini" class="datay" type="primary" @click="fetch">确定</el-button>
      <!-- 取消 -->
      <el-button size="mini" class="datay">重置</el-button>
    </div>

    <!-- 列表 -->
    <el-table size="mini" class="list" :data="tableData" border style="width: 100%" :header-cell-style="{background:'#ccc'}">
      <el-table-column prop="userTypeName" label="变更类型"></el-table-column>
      <el-table-column prop="ipAddress" label="操作账号"></el-table-column>
      <el-table-column prop="ip" label="被操作账号"></el-table-column>
      <el-table-column prop="createTime" label="操作类容"></el-table-column>
      <el-table-column prop="Time" label="操作时间"></el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      size="mini"
      class="pageNumage"
      @current-change="handleCurrentChange"
      background
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import { getList } from "@/api/table";
import { optLog, Logtype } from "@/api/user";
import qs from "qs";
export default {
  data() {
    return {
      selection: "定盘设置",
      dataTime: "",
      keyword: "", //搜索
      pageNum: 1,
      options: [], //变更类型
      total: 0,
      tableData: [],
      startTime: "", //开始时间
      endTime: "", //结束时间
      change:"1"
    };
  },
  created() {
    this.fetchData();
    this.list();
  },
  methods: {
    //   分页
    handleCurrentChange(val) {
      this.pageNum = val;
      this.list();
    },
    // 变更类型id
    Changetype(type){
       this.change = type
    },
    // 时间
    getSTime(val) {
      this.dataTime = val;
      console.log(this.dataTime, "日期");
    },
    // 接口数据
    fetchData() {
      let data = qs.stringify({});
      Logtype(data).then(res => {
        console.log(res.data, "类型");
        if (res.data.code == 200) {
          this.options = res.data.data;
        }
      });
    },
    // 列表
    list() {
      let data = qs.stringify({
        pageNum: this.pageNum,
        pageSize: 10,
        type: this.change,
        startTime: this.startTime,
        endTime: this.endTime,
        beOptAccount: this.keyword
      });
      optLog(data).then(res => {
        console.log(res.data, "日记列表");
        if (res.data.code == 200) {
          this.tableData = res.data.data;
          this.total = res.data.count;
        }
      });
    },
    // 确定
    fetch() {
      this.list();
    }
  }
};
</script>
<style lang="less" scoped>
.search {
  padding: 0 20px;
  margin-top: 20px;
  display: flex;
  align-items: center;
  .datay {
    margin-left: 20px !important;
  }
}
// 列表
.list {
  margin-left: 20px;
  margin-top: 20px;
}
// 分页
.pageNumage {
  float: right;
  margin-top: 20px;
}
</style>
